﻿/* File Created: 三月 19, 2014 */
(function ($) {
    $.report = {};
    $.extend($.report,
    {
        init: function (set) {
            var curDate = new Date();
            var beginDateStr = curDate.getFullYear() + '-' + (curDate.getMonth() + 1) + '-' + curDate.getDate();
            var endDate = new Date(new Date(beginDateStr).valueOf() + (-7 * 24 * 60 * 60 * 1000));
            var endDateStr = endDate.getFullYear() + '-' + (endDate.getMonth() + 1) + '-' + endDate.getDate();
            $.ajax({
                type: "GET",
                url: llb_global.config.api + "common/Get_AllReport",
                data: {
                    beginDateTime: endDateStr,
                    endDateTime: beginDateStr
                },
                success: function (data) {
                    data = JSON.parse(data);
                    if (data) {
                        if (data.state === "success") {
                            set.xAxisData = [], set.seriesData = {
                                coupon310: [],
                                coupon310used: [],
                                coupon310share: [],
                                coupon200: [],
                                coupon200used: []
                            };
                            for (var i = 0; i < data.data.length; i++) {
                                set.xAxisData.push(data.data[i].StatisticsDate);
                                set.seriesData.coupon310.push(data.data[i].Coupon310Count);
                                set.seriesData.coupon310used.push(data.data[i].Coupon310UsedCount);
                                set.seriesData.coupon310share.push(data.data[i].Coupon310ShareCount);
                                set.seriesData.coupon200.push(data.data[i].Coupon200Count);
                                set.seriesData.coupon200used.push(data.data[i].Coupon200UsedCount);
                            }
                            $.report.utils.show310(set);
                            $.report.utils.show310used(set);
                            $.report.utils.show200(set);
                        }
                    }
                }
            });
        },
        utils: {
            show310: function (set) {
                var colors = ['#5793f3', '#d14a61'];
                var myChart = echarts.init(document.getElementById("coupon310"));
                var options = {
                    color: colors,
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross'
                        }
                    },
                    title: {
                        text: "310元购车券统计"
                    },
                    legend: {
                        data: ["310发放量",  "310转发量"]
                    },
                    xAxis: {
                        data: set.xAxisData
                    },
                    yAxis: [
                         {
                             type: 'value',
                             name: '数量',
                             position: 'left',
                             axisLine: {
                                 lineStyle: {
                                     color: colors[0]
                                 }
                             },
                             axisLabel: {
                                 formatter: '{value} 个'
                             }
                         },
                         
                         {
                             type: 'value',
                             name: '数量',
                             position: 'left',
                             axisLine: {
                                 lineStyle: {
                                     color: colors[1]
                                 }
                             },
                             axisLabel: {
                                 formatter: '{value} 个'
                             }
                         }
                    ],
                    series: [
                        {
                            name: "310发放量",
                            type: "bar",
                            data: set.seriesData.coupon310
                        },
                        {
                            name: "310转发量",
                            type: "bar",
                            data: set.seriesData.coupon310share
                        }
                    ]
                };
                myChart.setOption(options);
            },
            show310used: function (set) {
                var colors = ['#5793f3'];
                var myChart = echarts.init(document.getElementById("coupon310used"));
                var options = {
                    color: colors,
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross'
                        }
                    },
                    title: {
                        text: "310元购车券核销量统计"
                    },
                    legend: {
                        data: ["310核销量"]
                    },
                    xAxis: {
                        data: set.xAxisData
                    },
                    yAxis: [
                         {
                             type: 'value',
                             name: '核销量',
                             position: 'left',
                             axisLine: {
                                 lineStyle: {
                                     color: colors[0]
                                 }
                             },
                             axisLabel: {
                                 formatter: '{value} 个'
                             }
                         }
                    ],
                    series: [
                        {
                            name: "310核销量",
                            type: "line",
                            data: set.seriesData.coupon310used
                        }
                    ]
                };
                myChart.setOption(options);
            },
            show200: function (set) {
                var colors = ['#5793f3', '#d14a61'];
                var myChart = echarts.init(document.getElementById("coupon200"));
                var options = {
                    color: colors,
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross'
                        }
                    },
                    title: {
                        text: "200元工时券统计"
                    },
                    legend: {
                        data: ["工时券发放量", "工时券核销量"]
                    },
                    xAxis: {
                        data: set.xAxisData
                    },
                    yAxis: [
                         {
                             type: 'value',
                             name: '数量',
                             position: 'left',
                             axisLine: {
                                 lineStyle: {
                                     color: colors[0]
                                 }
                             },
                             axisLabel: {
                                 formatter: '{value} 个'
                             }
                         },
                         {
                             type: 'value',
                             name: '数量',
                             position: 'left',
                             axisLine: {
                                 lineStyle: {
                                     color: colors[1]
                                 }
                             },
                             axisLabel: {
                                 formatter: '{value} 个'
                             }
                         }
                    ],
                    series: [
                        {
                            name: "工时券发放量",
                            type: "line",
                            data: set.seriesData.coupon200
                        },
                        {
                            name: "工时券核销量",
                            type: "bar",
                            data: set.seriesData.coupon200used
                        }
                    ]
                };
                myChart.setOption(options);
            }
        }
    });
})(jQuery);
